package com.example.toolbar.fragment;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.toolbar.LoginActivity;
import com.example.toolbar.R;
import com.example.toolbar.net.HttpRequestWrap;
import com.example.toolbar.net.OnResponseHandler;
import com.example.toolbar.net.RequestHandler;
import com.example.toolbar.net.RequestStatus;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class fragmenttest extends Fragment {
	private HttpRequestWrap httpRequest;
	Activity activity;

	@Override
	@Nullable
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.qunimade, null);
		activity = this.getActivity();
		httpRequest = new HttpRequestWrap(activity);
		Button button = (Button) view.findViewById(R.id.send);
		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				httpRequest.setMethod(HttpRequestWrap.GET);
				httpRequest.setCallBack(new RequestHandler(activity,
						new OnResponseHandler() {

							@Override
							public void onResponse(String result,
									RequestStatus status) {
								// TODO Auto-generated method stub
								if (status == RequestStatus.SUCCESS) {
									JSONObject obj = JSON.parseObject(result);
									if (!obj.getBooleanValue("success")) {
										// ����ʧ��
										Toast.makeText(activity,
												obj.getString("message"),
												Toast.LENGTH_SHORT).show();
									} else {
										// ����ɹ�
										Toast.makeText(activity, result,
												Toast.LENGTH_SHORT).show();
									}
								}
							}
						}));
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("page","1");
				params.put("rows","5");
				params.put("status", "PROCESSED");
				httpRequest.send("http://tr.zzapi.gson.cn/api/user/comments?page=1&rows=10");
			}
		});
		return view;
	}
}
